﻿///***************************************************************
/// 시  스  템 : Updms.Mny
/// 단위시스템 : MNY
/// 계      층 : Presentation Layer
/// 프로그램명 : Mny3011p
/// 파  일  명 : Mny3011p.aspx.cs
/// 설      명 : 잔액검증
///***************************************************************
/// 수정ID 일자       이름     내용
///---------------------------------------------------------------
/// CH001  2010-03-09 송시명   최초 작성
///***************************************************************
using System;
using System.Data;
using System.Web.UI;

using SMFramework.Data;
using SMFramework.Utility;

using Base.Dac;
using Updms.Mny.Exe;


namespace Updms.Mny
{
	public partial class Mny3011p : Updms.Common.BaseClass.PageBase
	{
		#region 전역영역

		//프로그램상수
		public static readonly string PID = "Mny3011p";
		public static readonly string gs_path_info = "/updms/Mny/" + PID + ".aspx";

		Global global = new Global();

		//검색
		protected string kw1 = "";	//년월
		protected string kw2 = "";	//잔액

		// 페이지모드
		private string gs_page_mode = "";

		#endregion

		#region Page_Load, OnPageLoad

		protected void Page_Load(object sender, EventArgs e)
		{
			SetInit();
			if (!Page.IsPostBack)
			{
				// 최초 화면 로딩시 처리해야 할 부분
				OnPageLoad();
			}
		}

		// OnPageLoad
		private void OnPageLoad()
		{
			SetLiterals(global.GetLabelInfoByPgmId(PID, LANG_SET));
			SetClientScript();
			SetBaseYearMonth();
			SetSearchParameter();
		}

		#endregion

		#region InitializeComponent

		private void InitializeComponent()
		{
			this.Load += new System.EventHandler(this.Page_Load);
			this.PreRender += new System.EventHandler(this.Page_PreRender);
		}

		#endregion

		#region SetClientScript

		private void SetClientScript()
		{
			//onKeyUp이벤트
			txt_search_balance.Attributes.Add("onkeyup", "document.form1.txt_search_balance.value=addComma(document.form1.txt_search_balance.value);");
		}

		#endregion

		#region SetInit, SetSearchParameter

		//초기값설정
		private void SetInit()
		{
			lbl_search_flag.Text = "INIT";
		}

		//검색파라미터
		private void SetSearchParameter()
		{
			switch (lbl_search_flag.Text.Trim().ToUpper())
			{
				case "INIT":
					if (String.IsNullOrEmpty(Request.QueryString["kw1"]))
					{
						kw1 = txt_search_base_ym.Text.Trim();
					}
					else
					{
						kw1 = Server.UrlDecode(Request.QueryString["kw1"]);
						txt_search_base_ym.Text = kw1;
					}

					if (String.IsNullOrEmpty(Request.QueryString["kw2"]))
					{
						kw2 = txt_search_balance.Text.Trim();
					}
					else
					{
						kw2 = ConversionUtil.ExtractNumberStr(Server.UrlDecode(Request.QueryString["kw2"]));
						txt_search_balance.Text = kw2;
					}

					break;
				case "SEARCH":
					kw1 = String.IsNullOrEmpty(txt_search_base_ym.Text) ? DateUtil.GetNow("yyyy-MM") : txt_search_base_ym.Text.Trim();
					kw2 = ConversionUtil.ExtractNumberStr(txt_search_balance.Text.Trim());
					break;
			}
		}

		#endregion

		#region 마스터 Method (SetBaseYearMonth)

		//년월
		private void SetBaseYearMonth()
		{
			txt_search_base_ym.Text = DateUtil.GetNow("yyyy-MM");
		}

		#endregion

		#region 디테일 Method ()

		#endregion

		#region CRUD (SelectProcess, SearchProcess)

		//조회
		private void SelectProcess()
		{
			DataSet lo_ds = new DataSet();
			DataPack lo_dp = new DataPack();

			//검색
			lo_dp.AddProperty("ls_base_ym", typeof(string), kw1);
			lo_dp.AddProperty("li_balance", typeof(string), kw2);

			using (Mny3011p_NT _Mny3011p_NT = new Mny3011p_NT())
			{
				lo_ds.Merge(_Mny3011p_NT.CheckBalance(lo_dp));
				lbl_gap_amount.Text = ConversionUtil.AddComma(DataSetUtil.GetFldStr(lo_ds, "UPDMS_MNY_IN_OUT_MGT", "Gap_Amount"));
			}
		}

		//검색
		private void SearchProcess()
		{
			gs_page_mode = "R";
			lbl_search_flag.Text = "SEARCH";
			SetSearchParameter();
			SelectProcess();
		}

		#endregion		

		#region Page_PreRender, ChangePageMode

		// Page_PreRender
		private void Page_PreRender(object sender, System.EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				using (AccessCheck access = new AccessCheck())
				{
					//접근권한 체크
					if (!access.CheckPgmAccessGrant(PID, USER_ID, ACCESS_LOG_INFO))
					{
						Response.Redirect(URL_NO_AUTHORITY_REDIRECT_POPUP);	//사용자의 권한은 요청하신 페이지를 볼 수 없습니다
					}
				}
			}
			ChangePageMode();
		}

		// ChangePageMode
		private void ChangePageMode()
		{
			switch (gs_page_mode)
			{
				case "":	//처음 페이지로드시
					table_detail_1.Visible = false;
					break;
				case "R":	//검색버튼 클릭시
					table_detail_1.Visible = true;
					break;
			}
		}

		#endregion

		#region 버튼이벤트

		//검색
		protected void ibtn_search_Click(object sender, EventArgs e)
		{
			SearchProcess();
		}

		#endregion


	}
}
